package de.dopichaj.labrador.index.lucene;

import java.io.IOException;

import org.apache.lucene.document.Document;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.HitCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searchable;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.search.Weight;

/**
 * A Searchable that searches one Searchable, but delegates {@link #docFreq} and
 * {@link #docFreqs(Term[])} to another Searchable. 
 */
public final class IdfDelegatingSearchable implements Searchable {

    private final Searchable searchable;
    private final Searchable idfProvider;
    
    /**
     * Creates a Searchable that delegates to two other Searchables.
     * @param searchable
     *      The Searchable to use for all methods but {@link #docFreq(Term)} and
     *      {@link #docFreqs(Term[])}.
     * @param idfProvider
     *      The Searchable to use for {@link #docFreq(Term)} and
     *      {@link #docFreqs(Term[])}.
     */
    public IdfDelegatingSearchable(Searchable searchable, Searchable idfProvider) {
        this.searchable = searchable;
        this.idfProvider = idfProvider;
    }

    public int docFreq(Term arg0) throws IOException {
        return idfProvider.docFreq(arg0);
    }

    public int[] docFreqs(Term[] arg0) throws IOException {
        return idfProvider.docFreqs(arg0);
    }

    public void close() throws IOException {
        searchable.close();
    }

    public Document doc(int arg0) throws IOException {
        return searchable.doc(arg0);
    }

    @SuppressWarnings("deprecation")
    public Explanation explain(Query arg0, int arg1) throws IOException {
        return searchable.explain(arg0, arg1);
    }

    public Explanation explain(Weight arg0, int arg1) throws IOException {
        return searchable.explain(arg0, arg1);
    }

    public int maxDoc() throws IOException {
        return searchable.maxDoc();
    }

    public Query rewrite(Query arg0) throws IOException {
        return searchable.rewrite(arg0);
    }

    @SuppressWarnings("deprecation")
    public void search(Query arg0, Filter arg1, HitCollector arg2)
        throws IOException {
        searchable.search(arg0, arg1, arg2);
    }

    @SuppressWarnings("deprecation")
    public TopFieldDocs search(Query arg0, Filter arg1, int arg2, Sort arg3)
        throws IOException {
        return searchable.search(arg0, arg1, arg2, arg3);
    }

    @SuppressWarnings("deprecation")
    public TopDocs search(Query arg0, Filter arg1, int arg2) throws IOException {
        return searchable.search(arg0, arg1, arg2);
    }

    public void search(Weight arg0, Filter arg1, HitCollector arg2)
        throws IOException {
        searchable.search(arg0, arg1, arg2);
    }

    public TopFieldDocs search(Weight arg0, Filter arg1, int arg2, Sort arg3)
        throws IOException {
        return searchable.search(arg0, arg1, arg2, arg3);
    }

    public TopDocs search(Weight arg0, Filter arg1, int arg2)
        throws IOException {
        return searchable.search(arg0, arg1, arg2);
    }
}
/*
Copyright (c) 2005 Benedikt Eger
Copyright (c) 2005-2007 Philipp Dopichaj

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/